package com.skit.mine.viewmodel

import android.view.View
import androidx.databinding.ObservableField
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.SavedStateHandle
import com.skit.common.base.BaseViewModel
import com.skit.common.bean.User
import com.skit.common.http.NetResult
import com.skit.mine.data.PersonRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject


data class ActivityNum(
    val shenhe: Int? = 0,
    val kaishi: Int? = 0,
    val jingxing: Int? = 0,
    val all: Int? = 0
)

@HiltViewModel
class PersonViewModel @Inject constructor(
    private val repository: PersonRepository
) :
    BaseViewModel() {
    //    private val repository: PersonRepository = PersonRepository()
    var loginClickListener: ObservableField<View.OnClickListener> =
        ObservableField<View.OnClickListener>()

    private val _activityNum = MutableLiveData<ActivityNum>()
    private val _user = MutableLiveData<User>()
    private val _userDataLiveData = MutableLiveData<NetResult<User>>()
    val activityNum: LiveData<ActivityNum> = _activityNum
    val user: LiveData<User> = _user
    val userDataLiveData: LiveData<NetResult<User>> = _userDataLiveData

    init {
        _activityNum.value = ActivityNum()
        _user.value = null
    }

    fun setActivityNums(activityNum: ActivityNum) {
        _activityNum.value = activityNum
    }

    fun setUser(user: User?) {
        _user.value = user
    }

    fun getUserData(id: Int, token: String) {
        netResult({
            repository.getUserInfo(id, token)
        }) {
            _userDataLiveData.value = it
        }
    }
}